// pages/personal/myordersale/myordersale.js
var utils = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentPage:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        that.setData({
            orderState:options.stateid
        })
        that.onOrderList(that.data.currentPage)
    },
    onOrderList: function (currentPage) {
        var that = this;
        utils.showLoading();
        utils.http("api/v1/order/my_order_list", { order_state: that.data.orderState, page:currentPage }, function (res) {
            utils.hideLoading();
            console.log(res.datas);
            var allpost = that.data.orderList;
            if (allpost == undefined) {
                allpost = [];
            }
            for (var i in res.datas) {
                res.datas[i].number = 0;
                allpost.push(res.datas[i])
            }
            if (res.datas.length < 10) {
                that.setData({
                    tishi_title: '已加载全部',
                });
            } else {
                that.setData({
                    tishi_title: '加载更多',
                });
            }
            that.setData({
                orderList: allpost,
                ready: res.datas.length == 0 ? 1 : 2,
            })
        })
    },
    //订单详情
    onOrderDetailsTap: function (e) {
        wx.navigateTo({
            url: '../myorderdetails/myorderdetails?id=' + e.currentTarget.id,
        })
    },
    onReachBottom: function () {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            that.onOrderList(page)
        }
    },
})